<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>2048</title>
  <script src="2048.js"></script>
  <script>
      let board = [
        [0,0,0,0,],
        [0,0,0,2,],
        [0,0,0,8,],
        [0,2,4,16]
      ];

      board = [
        [2,0,0,2,],
        [0,0,0,0,],
        [0,0,0,0,],
        [8,4,0,0]
      ];
      
      board = [
        [4,4,8,2,],
        [8,16,128,32,],
        [64,2,256,2,],
        [2,32,64,4]
      ];

      board = [
        [2,4,2,2,],
        [4,8,64,8,],
        [4,16,512,32,],
        [16,64,256,8]
      ];

      board = [
        [128,128,2,2,],
        [4,2,4,2,],
        [4,2,4,2,],
        [0,2,4,0,],
      ];
      
      
      board = [
        [4,16,32,2,],
        [2,2,0,0,],
        [0,0,0,0,],
        [0,0,0,0,],
      ];

      // board = [
      //   [4,2,0,0,],
      //   [16,2,0,0,],
      //   [32,0,0,0,],
      //   [2,0,0,0,],
      // ];

      function buildMatrix(boardStr){
        const matrix = [];
        let row = [];
        const items = boardStr.split(',');
        for (let i = 0; i < 16; i++) {
          let j = (i + 1) % 4;
          row.push(items[i] - 0);
          if (i > 0 && j == 0) {
            matrix.push([...row])
            row = [];
          }
          
        }
        // console.log(matrix);
        return matrix;
      }
      // let boardStr = '0,0,0,2,0,0,0,0,0,0,2,2,8,256,64,16,';
      // board = buildMatrix(boardStr);

      board = [
        [4,4,0,0,],
        [4,4,0,0,],
        [0,0,0,0,],
        [0,0,0,0,],
      ];

      boardStr = '4,0,0,0,4,0,0,0,4,16,2,0,4,32,4,2';
      boardStr = '4,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0';
      boardStr = '4,8,4,0,4,4,0,0,2,0,0,0,0,0,0,0';
      boardStr = '0,0,0,4,2,0,2,128,0,2,8,16,0,0,4,8';
      board = buildMatrix(boardStr);
      

  </script>
</head>
<body>
  <button onclick="EPAM_2048_Hero(board);">Test</button>
  <button onclick="addItemToMatrix(board);">addItemToMatrix</button>
  <button onclick="calculateWeight(board);">calculate Weight</button>
</body>
</html>